package com.harisucici.jetpackbase.view;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.DialogFragment;

import com.harisucici.jetpackbase.R;
import com.harisucici.jetpackbase.databinding.DialogLoadingBinding;
import com.zackratos.ultimatebarx.library.UltimateBarX;

public class DialogLoading extends DialogFragment {
    DialogLoadingBinding mBinding;
    public static String TAG = "DIALOG_LOADING";
    public static String TITLE = "TITLE";


    public static DialogLoading newInstance(String title) {
        DialogLoading fragment = new DialogLoading();
        Bundle bundle = new Bundle();
        bundle.putString(TITLE, title);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        mBinding = DataBindingUtil.inflate(inflater, R.layout.dialog_loading, container, false);
        mBinding.title.setText(getArguments().getString(TITLE));
        return mBinding.getRoot();
    }

    @Override
    public void onStart() {
        super.onStart();
        Window window = getDialog().getWindow();
        WindowManager.LayoutParams windowParams = window.getAttributes();
        windowParams.dimAmount = 0.0f;
        window.setAttributes(windowParams);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        UltimateBarX.create(UltimateBarX.STATUS_BAR).transparent().fitWindow(true).apply(this);
        UltimateBarX.create(UltimateBarX.NAVIGATION_BAR).transparent().fitWindow(false).apply(this);
    }
}